﻿//MyEditGrid = Ext.extend(Ext.grid.EditorGridPanel,{
//  ex_ds:null,
//  initComponent : function() {
//    var pageSize=(this.ex_datacfg.pageSize==null)?Star.DEFAULT_PAGE_SIZE:this.ex_datacfg.pageSize;
//    this.ex_ds = Star.createDataStore(this.ex_datacfg.metas, {
//	  url : this.ex_datacfg.facade,method:this.ex_datacfg.method,
//	  sortField : this.ex_datacfg.sortField,
//	  sortDir : this.ex_datacfg.sortDir,
//	  limit:pageSize
//	});
//	this.ex_ds.on('beforeload', this.ex_datacfg.query);
//	var queryRecords = new Ext.Action({
//	  text : Star_Info.QUERY,
//	  iconCls : 'crud-query',
//	  tooltip : Star_Info.QUERY_TIP,
//	  handler : function() {
//		this.ex_ds.reload();
//	  },
//	  scope:this
//	});
//	var selMode=new Ext.grid.CheckboxSelectionModel();
//	var tbarCfg=[];
//	if(this.ex_queryCfg!=null) {
//		tbarCfg=this.ex_queryCfg.concat(['-', queryRecords]);
//	    if(this.ex_buttonsToRight===true) tbarCfg=this.ex_queryCfg.concat(['-', queryRecords,'->']);
//	}
//    if(this.tbar!=null){
//      // Star.log(this.tbar);
//        tbarCfg=this.tbar;
//     //   Star.log(tbarCfg);
//     }
//	var columns = [new Ext.grid.RowNumberer(),selMode].concat(Star.makeColumns(this.ex_datacfg.metas));
//	//columns = Star.makeColumns(this.ex_datacfg.metas);
//    Ext.apply(this,{loadMask : new Ext.LoadMask(Ext.getBody(),{msg:Star_Info.LOAD_MASK_MSG}),
//	  sm:selMode,store : this.ex_ds,	columns : columns,clicksToEdit:1,
//	  viewConfig : {forceFit : true	},
//	  tbar:tbarCfg,
//	  bbar : new Ext.PagingToolbar({
//	    pageSize : pageSize,store : this.ex_ds,
//		displayInfo : this.ex_displayInfo,	plugins : [new Ext.ux.PageSizePlugin()]
//	  })
//	});
//    Ext.applyIf(this,{height :  400,width : 600, stripeRows : true,frame : true});
//	selMode.on("rowselect", function(me, rowIndex, rec) {
//	 // Star.log(rec.data);
//	  if(this.ex_SelectedRow!=null) this.ex_SelectedRow(rec.data);
//	  return true;
//	},this);
//    MyEditGrid.superclass.initComponent.call(this);	
//   //if(this.ex_datacfg.autoLoad==true) this.ex_ds.load();
//  },
//  initEvents: function() {
//	MyEditGrid.superclass.initEvents.call(this);	
//  },
//  Load:function() {
//    this.ex_ds.reload();
//  },
//  GetSelectedRecords:function() {
//     return this.getSelectionModel().getSelections();
//  }
//  
//});
//Ext.reg('MyEditGrid', MyEditGrid);
Ext.define('Kwan.ex.Grid', {
    extend: 'Ext.grid.Panel',
    border: false, forceFit: true, frame: true, layout: 'fit', columnLines: true, loadMask: true, al: true, // 自动加载
    viewConfig: {
        stripeRows: true
    },
    selType: 'checkboxmodel', //设定选择模式
    multiSelect: true, //运行多选
    //selModel: new Ext.selection.CheckboxModel, //添加checkbox列
    //selModel : Ext.create('Ext.selection.CheckboxModel'),
    noPagging: false,
    operBar: {}, // 操作栏
    modelFields: [],
    dataUrl: '',
    defSort: [],
    initComponent: function () {
        var cfg = this.ex_datacfg;
        this.store = Kwan.createDataStore(cfg.metas, {
            url: cfg.facade, method: cfg.method,
            sortField: cfg.sortField,
            sortDir: cfg.sortDir,
            limit: cfg.pageSize
        });

        this.buildFilters = function () {
            var filtersArray = [];
            Ext.each(this.columns, function (c) {
                if (c.noFilter != true) {
                    filtersArray[filtersArray.length] = {
                        dataIndex: c.dataIndex,
                        type: c.type
                    };
                }
            });
            return filtersArray;
        };
        this.features = [{
            ftype: 'filters',
            encode: true,
            menuFilterText: '检索',
            updateBuffer: 1000,

            filters: this.buildFilters()
        }];
        if (this.noPagging == false) {
            this.bbar = Ext.create('Ext.PagingToolbar', {
                store: this.store,
                pageSize: 20,
                displayInfo: true,
                plugins: Ext.create('Ext.ux.ProgressBarPager', {}),
                items: [{
                    icon: '/Admin/style/16Icons/lightning.png',
                    tooltip: '重置查询',
                    scope: this,
                    handler: function () {
                        this.filters.clearFilters();
                    }
                }, { xtype: "label", text: "每页显示:" }, { xtype: "tbspacer", width: 10 }, { xtype: "combo", width: 80, value: "20", editable: false, displayField: "text", valueField: "value", store: new Ext.data.SimpleStore({ fields: ["text", "value"], data: [["10", "10"], ["20", "20"], ["50", "50"], ["100", "100"]] }), submitValue: true, listeners: { select: { fn: function (item, record, index) { this.bbar.pageSize = parseInt(this.getValue()); this.bbar.doLoad(); } }}}],
                emptyMsg: "没有可显示的数据"
            });
        }

        this.tbar = this.operBar;
        this.callParent(arguments);
    },
    Load: function () {
        this.ex_ds.reload();
    },
    GetSelectedRecords: function () {
        return this.getSelectionModel().getSelections();
    }
});